<script lang="ts">
import { Vue, Component, Watch } from "vue-property-decorator";

@Component
export default class tableCommon extends Vue {
  pageSizes: Array<number> = [10, 20, 30, 40]; // 分页数组
  layout: string = "total, sizes, prev, pager, next, jumper"; // 分页顺序

  /** 数据占位 */
  page: any = {}; // 查询接口的参数，放置ide报错
  multiSelection: Array<any> = []; // 多选的数据
  recSceneList: Array<any> = [];
  portraitTypeList: Array<any> = [];
  defaultType: string = "default"; //最大化full ,最小化 default
  maxText: string = "最大化";

  /** 函数占位 */
  getTableData(): void {} // 更新table的数据

  get isEmptyMultiSelection(): boolean {
    return !this.multiSelection.length;
  }

  bindMaxHeightHalf(): string {
    // 立刻执行,画像开发用
    return window.innerHeight - 60 - 195 - 400 + "px";
  }
  bindMaxHeightAll(): string {
    // 立刻执行，其余页面表格用
    return window.innerHeight - 60 - 195 + "px";
  }

  handlerHeaderClass() {
    return "private-header-class";
  }

  handlerContAddItem(model: string): void {
    // @ts-ignore
    this[model + "Table"].push({ ioTable: "", model });
  }

  handlerContDelItem(model: string, key: number): void {
    // @ts-ignore
    this[model + "Table"].splice(key, 1);
  }

  getImportFileData(model: string, data: Array<any>): void {
    const [importFileData, importIndex] = data;
    const { tableName } = importFileData;
    // @ts-ignore
    this[model + "Table"][importIndex].ioTable = tableName;
  }

  //最大化和最小化
  handlerChangeBlock() {
    const coderRef: any = this.$refs.coderRef;
    const coderLogRef: any = this.$refs.coderLogRef;
    this.defaultType = this.defaultType == "default" ? "full" : "default";
    this.maxText = this.defaultType == "default" ? "最大化" : "最小化";
    if (this.defaultType == "full") {
      coderRef.setSize("900px");
      coderLogRef && coderLogRef.setSize("100%");
    } else {
      coderRef.setSize("300px");
      coderLogRef && coderLogRef.setSize("265px");
    }
  }

  // 点击某项,显示输入框,获取焦点
  clickScopeRow(item: any, type: string, refDom: any) {
    item[type + "Edit"] = true;
    setTimeout(() => {
      (this.$refs[refDom] as any).focus();
    }, 5);
  }
  // 多选
  handleSelectionChange(selection: Array<any>) {
    this.multiSelection = selection;
  }

  handleSizeChange(pageSize: number): void {
    Object.assign(this.page, { pageSize, pageNum: 1 });
  }

  handleCurrentChange(pageNum: number): void {
    Object.assign(this.page, { pageNum });
  }

  dateToString(time: any) {
    const thisTime = time.replace(/ /g, "/");
    const nowTime: any = new Date(thisTime);
    return nowTime.getTime();
  }

  @Watch("page", { deep: true })
  onPage(v: any) {
    v && this.getTableData();
  }
}
</script>
